<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class=" layui-form-item">
        <label class="layui-form-label">计划制定日期</label>
        <div class="layui-input-block" style="width:500px">
            <input type="text" name="Plandate"  id="Plandate" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">采购负责人</label>
        <div class="layui-input-inline">
            <input type="text" name="" placeholder="请输入" autocomplete="off" class="layui-input" id="demo3">
            <input type="hidden" name="dleaderId" id="dleaderId"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item  ">
        <label class="layui-form-label">计划备注</label>
        <div class="layui-input-block" style="width:500px">
            <textarea placeholder="请输入内容" class="layui-textarea" name="Planremark" id="Planremark"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>

<script>
    layui.use(['form','laydate','tableSelect'], function () {
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate,
            $ = layui.$,
            tableSelect=layui.tableSelect;
        //日期
        /*laydate.render({
            elem: '#Plandate',
            position: 'static'
        });*/
        laydate.render({
            elem: '#Plandate'
        });
        //监听新增订单提交按钮
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                type:"post",
                url:"/addPurchasePlan",
                data:{
                    purchaseDate:data.field.Plandate,
                    empId:data.field.dleaderId,
                    remark:data.field.Planremark
                },
                success:function(data){
                    var msg = data.msg;
                    layer.open({
                        title:['确认消息'],
                        content: msg,
                        btn: ['确定'],
                        shadeClose: true,
                        yes: function(index, layero){
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            window.parent.location.reload();//刷新父页面
                        }

                    })
                }

            })

            return false;
        });
        tableSelect.render({
            elem: '#demo3',
            checkedKey: 'id',
            height:'200',
            width:'450',
            searchType: 'more',
            searchList: [
                {searchKey: 'empName', searchPlaceholder: '搜索用户姓名'},
                {searchKey: 'empSex', searchPlaceholder: '搜索用户性别'},
            ],
            table: {
                url: '/emp/getempsBynum',
                cols: [[
                    { type: 'radio' },
                    { field: 'empId', title: 'ID' },
                    { field: 'empName', title: '姓名' },
                    { field: 'empSex', title: '性别' }
                ]],
                limit:6
            },
            done: function (elem, data) {
                var NEWJSON = []
                var list = []
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.empName)
                    list.push(item.empId)
                })
                elem.val(NEWJSON.join(","))
                $("#dleaderId").val(list)
            }
        })
        function closeSelf(){
            var i = window.parent.layer.getFrameIndex();
            window.parent.layer.close(i);
        }

    });
</script>
</body>
</html>